/*
 * 文件名：LTEDataAcceptServiceImpl.java
 * 版权：亚信科技(南京)版权所有
 * 描述：TODO
 * 修改人：napo
 * 修改时间：2015-12-14
 * 修改内容：TODO
 */
package com.ailk.bigdata.etl.realstream.server.protocal.sdtp.server.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ailk.bigdata.etl.realstream.server.constant.ProtocalSdtpConstant;
import com.ailk.bigdata.etl.realstream.server.model.RealStreamUnit;
import com.ailk.bigdata.etl.realstream.server.monitor.EventCounter;
import com.ailk.bigdata.etl.realstream.server.protocal.sdtp.netty.handler.LTESdtpAcceptedHandler;
import com.ailk.bigdata.etl.realstream.server.protocal.sdtp.netty.server.ProtocalSdtpDataAcceptServer;
import com.ailk.bigdata.etl.realstream.server.service.DataAcceptService;

/**
 * @description TODO
 * @author [xuwei3]
 * @version [版本号,2015-12-14]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class LTEDataAcceptServiceImpl implements DataAcceptService
{
	private static Logger logger = LoggerFactory.getLogger(LTEDataAcceptServiceImpl.class);

	private static Thread dataListenTh;

	/**
	 * @see com.ailk.bigdata.etl.realstream.server.service.DataAcceptService#initRealStreamAcceptService(com.ailk.bigdata.etl.realstream.server.monitor.EventCounter)
	 */
	@Override
	public void initRealStreamAcceptService(EventCounter eventCount, RealStreamUnit... params)
	{

		if (dataListenTh == null)
		{
			dataListenTh = new LTEDataAcceptListenThread(eventCount);
		}
		if (!dataListenTh.isAlive())
		{
			logger.info("启动[SDTP]数据接收线程.........");
			dataListenTh.start();
		}

	}
}

class LTEDataAcceptListenThread extends Thread
{
	private static Logger logger = LoggerFactory.getLogger(LTEDataAcceptListenThread.class);

	private EventCounter eventCounter;

	public LTEDataAcceptListenThread(EventCounter eventCounter)
	{
		this.eventCounter = eventCounter;
	}

	@Override
	public void run()
	{
		try
		{
			logger.info("实时流数据接收端口监听服务启动PORT[{}].........", ProtocalSdtpConstant.PORT_SDTP_LTE_DATA_ACCEPT);
			new ProtocalSdtpDataAcceptServer(ProtocalSdtpConstant.PORT_SDTP_LTE_DATA_ACCEPT).runLTEServer(new LTESdtpAcceptedHandler(eventCounter));
		}
		catch (Exception e)
		{
			logger.error("实时流数据接收端口监听服务启动异常,系统推出登陆", e);
			System.exit(-1);
		}
	}
}
